﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[Global.Session_UserID] == null)
        {
            Response.Redirect("~/Login.aspx");
        }
        else
        {
            string strDisplayName = Session[Global.Session_UserDisplayName].ToString();
            lblLoginInfo.ToolTip = strDisplayName;
            if (strDisplayName.Length > 15 && strDisplayName.Length < 30)
            {
                lblLoginInfo.Text = strDisplayName;// +"<br/>(" + Session[Global.Session_UserTeamName].ToString() + "-" + Session[Global.Session_UserPhoneID].ToString() + ")";
            }
            else if (strDisplayName.Length >= 30)
            {
                lblLoginInfo.Text = strDisplayName.Substring(0, 27);// +"...<br/>(" + Session[Global.Session_UserTeamName].ToString() + "-" + Session[Global.Session_UserPhoneID].ToString() + ")";
            }
            else
            {
                lblLoginInfo.Text = Session[Global.Session_UserDisplayName].ToString();// +" (" + Session[Global.Session_UserTeamName].ToString() + "-" + Session[Global.Session_UserPhoneID].ToString() + ")";
            }
        }

        // Code that runs when a new session is started
        string _requestUrl = Request.Url.ToString();
        if (Session[Global.Session_IsPasswordExpired] != null)
        {
            if (Session[Global.Session_IsPasswordExpired].ToString() == "1")
            {
                if (!_requestUrl.Contains("/User/Default.aspx"))
                {
                    Response.Redirect("~/User/Default.aspx?rspCode=1001");
                }
            }
        }

        //if (Session[Global.Session_IsViewingCase] != null)
        //{
        //    if (Session[Global.Session_IsViewingCase].ToString() == "1")
        //    {
        //        if (!_requestUrl.Contains("/Entity/Default.aspx"))
        //        {
        //            if (!_requestUrl.Contains("Inbox/Search.aspx?action=SEARCH&form=POPUP")
        //                && !_requestUrl.Contains("AskACRA/Search.aspx?action=SEARCH&form=POPUP")
        //                && !_requestUrl.Contains("Message.aspx")
        //                )
        //            {
        //                Response.Redirect("~/Entity/Default.aspx?rspCode=1001");
        //            }
        //        }
        //        else
        //        {
        //            foreach (MenuItem item in NavigationMenu.Items)
        //            {
        //                if (item.Value != "KB")
        //                {
        //                    item.Enabled = false;
        //                }
        //            }
        //            txtMainSearch.Enabled = false;
        //            btnSearch.Enabled = false;
        //            hplSearch.Enabled = false;
        //        }
        //    }
        //}


        //My first CSS
        //HtmlLink myCSS = new HtmlLink();
        //myCSS.Href = "~/somecss1.css";
        //myCSS.Attributes.Add("rel", "stylesheet");
        //myCSS.Attributes.Add("type", "text/css");
        Literal litCss = new Literal();
        litCss.Text = FileReferenceUtil.GetFilePath(this.Page, "~/Styles/Site.css", 2);
        Page.Header.Controls.Add(litCss);

        Literal litJs = new Literal();
        litJs.Text = FileReferenceUtil.GetFilePath(this.Page, "~/Scripts/ValidationEffect.js", 1);
        Page.Header.Controls.Add(litJs);

        litJs.Text = FileReferenceUtil.GetFilePath(this.Page, "~/Scripts/CheckFormChanged.js", 1);
        Page.Header.Controls.Add(litJs);

        //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MySiteCss", FileReferenceUtil.GetFilePath(this.Page, "~/Styles/Site.css", 2));

    }


    protected void PagePreRender(object sender, EventArgs e)
    {

    }

    protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Entity/Search.aspx?q=" + txtMainSearch.Text);
    }
}
